package com.quanshi.shopping_search_api.rocketmq;

import com.quanshi.shopping_common.constant.Constant;
import com.quanshi.shopping_common.entity.GoodsDesc;
import com.quanshi.shopping_common.service.ISearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;


@Component
@RocketMQMessageListener(
        consumerGroup = Constant.SYNC_GOODS_CONSUMER_GROUP,
        topic = Constant.SYNC_GOODS_QUEUE
)
@Slf4j
public class SyncGoodsListener implements RocketMQListener<GoodsDesc> {


    @Autowired
    private ISearchService searchService;

    @Override
    public void onMessage(GoodsDesc goodsDesc) {
        if(Objects.nonNull(goodsDesc)){
            log.info("goodsDesc ： {}",goodsDesc);
            searchService.syncGoodsToES(goodsDesc);
        }
    }
}
